<template>
  <div class="import">
    <h2>员工导入</h2>
    <el-alert
      title="每次导入仅可添加1000名员工，姓名、手机、入职时间、聘用形式为必填项"
      type="warning"
      show-icon
      :closable="false"
    />
    <UploadExcel :on-success="succeccHdler" />
  </div>
</template>

<script>
import UploadExcel from '@/components/UploadExcel/index.vue'
import { formatExcelDate } from '@/utils/index'
import { importEmployees } from '@/api/employee'
export default {
  name: 'Import',
  components: {
    UploadExcel
  },
  methods: {
    // 导入
    async succeccHdler(data) {
      const newArr = data.results.map(v => {
        v.correctionTime = formatExcelDate(v.correctionTime, '-')
        v.timeOfEntry = formatExcelDate(v.timeOfEntry, '-')
        return {
          ...v
        }
      })
      await importEmployees(newArr)
      this.$message.success('批量导入成功')
      this.$router.push({ path: '/employees' })
    }
  }
}
</script>

<style lang="scss">
.import {
  background-color: #fff;
  padding: 25px 25px 60px 25px;

  h2 {
    color: #303133;
    text-align: center;
  }
  p {
    line-height: 20px;
    font-size: 14px;
    span {
      color: red;
    }
  }
}
</style>
